package demo1;

class Animal {
    public String name;
    public String color;

    public Animal(String name) {
        this.name = name;
    }
}

class Dog extends Animal {
    public Dog(String name) {
        super(name);
    }

    public void eat() {
        System.out.println("吃狗粮！");
    }
}

class Bird extends Animal {
    public Bird(String name) {
        super(name);
    }

    public void fly() {
        System.out.println("正在飞！");
    }
}

/*
public class demo1.Test2 {
     public static void main(String[] args) {
         demo1.Animal animal1 = new demo1.Dog("小狗");
         demo1.Bird bird = (demo1.Bird) animal1;
         bird.fly();
     }
 }
*/
public class Test2 {
    public static void main(String[] args) {
        Animal animal1 = new Dog("小狗");
        if (animal1 instanceof Bird) {
            Bird bird = (Bird) animal1;
            bird.fly();
        } else {
            System.out.println("不能飞！");
        }
    }
}
